package ltu.temp;

import java.util.ArrayList;

import android.app.ListActivity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;


	public class AllLocationActivity extends ListActivity {
		public static final String PREFS_LOCATION = "LocationPrefsFile";
	    @Override
		public void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);
	          
	        XmlParser test = new XmlParser();
	        ArrayList allTemp = test.fetchLocation();
	        
	        String[] tempList =  (String[]) allTemp.toArray(new String[allTemp.size()]);
	        
	        setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, tempList));

	        ListView lv = getListView();
	        lv.setTextFilterEnabled(true);
	        
	        lv.setOnItemClickListener(new OnItemClickListener() {
	            public void onItemClick(AdapterView<?> parent, View view,
	                int position, long id) {
	              // When clicked, show a toast with the TextView text
	            	
	            	SharedPreferences settings = getSharedPreferences(PREFS_LOCATION, 0);
	                SharedPreferences.Editor editor = settings.edit();
	                editor.putString("Location", (String) ((TextView) view).getText());
	                // Commit the edits!
	                editor.commit();
	            	
	              Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
	                  Toast.LENGTH_SHORT).show();
	            }
	          });
	    }
	    
	    
	
}
